package com.star.spring.deferred.service.completable;


import com.star.spring.deferred.utils.CommonUtils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @description: 编排demo
 * @author: star
 * @create: 2024-12-22 23:39
 **/

public class ThenComposeDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> stringCompletableFuture = CompletableFuture.supplyAsync(() -> {
            CommonUtils.log("supply正在休眠");
            CommonUtils.sleep(3);
            return "hello";
        }).thenCompose(result -> {
            CommonUtils.log("正在compose");
            return CompletableFuture.supplyAsync(() -> {
                CommonUtils.sleep(3);
                return result + " world";
            });
        });

        String s = stringCompletableFuture.get();
        CommonUtils.log(s);

    }
}
